import './globalErrorHandler';

import Koa from 'koa';
import Router from '@koa/router';
import koaBodyParser from 'koa-bodyparser';
import koaCors from '@koa/cors';
import routes from './router';

const app = new Koa();
const router = new Router();

router.get('/', (ctx) => {
    ctx.body = {
        code: 200,
        message: '打印服务已开启'
    };
});

app.use(
    koaCors({
        origin: '*',
        allowMethods: ['get', 'post'],
        allowHeaders: ['Content-Type', 'x-access-token']
    })
);
app.use(koaBodyParser());
router.use(routes.routes(), routes.allowedMethods());
app.use(router.routes()).use(router.allowedMethods());

app.listen(3689, () => {
    console.log(`Koa server is listening on port ${3689}`);
});
